package com.ruoyi.project.order.type.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.order.type.domain.PreOrderType;
import com.ruoyi.project.order.type.service.IPreOrderTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 预订方式Controller
 * 
 * @author yyj
 * @date 2021-05-13
 */
@Controller
@RequestMapping("/order/type")
public class PreOrderTypeController extends BaseController
{
    private String prefix = "order/type";

    @Autowired
    private IPreOrderTypeService preOrderTypeService;

    @RequiresPermissions("order:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询预订方式列表
     */
    @RequiresPermissions("order:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PreOrderType preOrderType)
    {
        startPage();
        List<PreOrderType> list = preOrderTypeService.selectPreOrderTypeList(preOrderType);
        return getDataTable(list);
    }

    /**
     * 导出预订方式列表
     */
    @RequiresPermissions("order:type:export")
    @Log(title = "预订方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PreOrderType preOrderType)
    {
        List<PreOrderType> list = preOrderTypeService.selectPreOrderTypeList(preOrderType);
        ExcelUtil<PreOrderType> util = new ExcelUtil<PreOrderType>(PreOrderType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增预订方式
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预订方式
     */
    @RequiresPermissions("order:type:add")
    @Log(title = "预订方式", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PreOrderType preOrderType)
    {
        return toAjax(preOrderTypeService.insertPreOrderType(preOrderType));
    }

    /**
     * 修改预订方式
     */
    @GetMapping("/edit/{preOrderTypeId}")
    public String edit(@PathVariable("preOrderTypeId") Long preOrderTypeId, ModelMap mmap)
    {
        PreOrderType preOrderType = preOrderTypeService.selectPreOrderTypeById(preOrderTypeId);
        mmap.put("preOrderType", preOrderType);
        return prefix + "/edit";
    }

    /**
     * 修改保存预订方式
     */
    @RequiresPermissions("order:type:edit")
    @Log(title = "预订方式", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PreOrderType preOrderType)
    {
        return toAjax(preOrderTypeService.updatePreOrderType(preOrderType));
    }

    /**
     * 删除预订方式
     */
    @RequiresPermissions("order:type:remove")
    @Log(title = "预订方式", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(preOrderTypeService.deletePreOrderTypeByIds(ids));
    }
}
